public class code3 {
    public int maxProduct(int[] nums) {
        int n = nums.length;

        int[] f = new int[n+1];//以i位置为结果的所有子数组的最大乘积
        int[] g = new int[n+1];//以i位置为结果的所有子数组的最小乘积

        f[0] = g[0] = 1;

        int ret = Integer.MIN_VALUE;
        for(int i=1;i<n+1;i++) {
            int x = nums[i-1],y = f[i-1]*nums[i-1],z = g[i-1]*nums[i-1] ;
            f[i] = Math.max(x,Math.max(y,z));
            g[i] = Math.min(x,Math.min(y,z));
            ret = Math.max(ret,f[i]);
        }
        return ret;
    }
}
